#ifndef MAIN_H_
#define MAIN_H_

#include <allegro.h>
#include <assert.h>
#include <stdio.h>

#define SEMAPHORE_NAME "towerhack" // for client-server IPC

extern BITMAP* buffer;

// gfx related defines
#define GFX_MODE GFX_AUTODETECT_WINDOWED
//#define GFX_MODE GFX_AUTODETECT_FULLSCREEN
#define TILE_SIZE 16
#define SPRITE_W 16
#define SPRITE_SIZE SPRITE_W
#define SPRITE_H 24
#define DISPLAY_WIDTH 320  // width of the buffer bitmap
#define DISPLAY_HEIGHT 240 // height of the buffer bitmap
#define HOST_WIDTH 640     // width of the actual screen or window
#define HOST_HEIGHT 480    // height of the actual screen or window
#define SCALE_X (((float)HOST_WIDTH) / DISPLAY_WIDTH)
#define SCALE_Y (((float)HOST_HEIGHT) / DISPLAY_HEIGHT)
#define FPS 60
#define WINGFX_SET 2 // Index of the button/window skin to use globally
#define MOVE_PIXELS_PER_TICK 2

// restrictions on game content
#define MAX_PLAYERS 16
#define MAX_CHARACTERS MAX_PLAYERS
#define MAX_MONSTERS 1024
#define MAP_WIDTH 64
#define MAP_HEIGHT MAP_WIDTH
#define NUM_DUNGEON_SEGMENTS 10
#define PLAYER_HPINIT 100
#define N_MONSTER_TYPES 2

// log file names
#define LOGFILE_CLIENT "/tmp/towerhack.log"
#define LOGFILE_SERVER "/tmp/towerhackd.log"

// debug defines on or off
// do not override custom debug compile params
#ifndef TOWERHACK_DEBUG
	#define TOWERHACK_DEBUG 1
	#define TOWERHACK_DEBUG_ARENA 0 // the arena is a small map without randomness
	#define TOWERHACK_DEBUG_NETWORK 0 // log significant network traffic
	#define TOWERHACK_DEBUG_LOGIC 0
	#define TOWERHACK_DEBUG_OBJECTS 0
#endif

// which bin are we compiling again? client is default
#ifndef TARGET_SERVER
#ifndef TARGET_CLIENT
	#define TARGET_CLIENT 1
#endif
#endif

typedef enum {
	STATE_INITIAL, // application is initializing, loading resources etc.
	STATE_MENU,    // in main menu (client only)
	STATE_LOBBY,   // in lobby
	STATE_GAME,    // in main game
	STATE_QUIT     // exiting application
} ApplicationState;
extern ApplicationState main_state;

void change_state (ApplicationState new_state);

#if TOWERHACK_DEBUG
// while mouse_x ranges from 0 to HOST_WIDTH,
// buffer_x ranges from 0 to WIDTH
void mouse_get_coords (int* buffer_x, int* buffer_y, int* map_x, int* map_y,
                       int* tile_x, int* tile_y, int* subtile);
#endif

#endif
